package com.demo.demo;

import lombok.extern.java.Log;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

@Log
public class Test {

	private static final String resource_a = "A";
	private static final String resource_b = "B";

	public static void deadLock() {
		Thread a = new Thread(() -> {
			synchronized (resource_a) {
				System.out.println("Thread a get resource a");
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (resource_b) {
					System.out.println("Thread a get resource b");
				}
			}
		});

		Thread b = new Thread(() -> {
			synchronized (resource_b) {
				System.out.println("Thread b get resource b");
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				synchronized (resource_a) {
					System.out.println("Thread b get resource a");
				}
			}
		});
		a.start();
		b.start();
	}

	public static void main(String[] args) throws ExecutionException, InterruptedException {
//		deadLock();
		ExecutorService executorService = Executors.newSingleThreadExecutor();
		Future<?> future = executorService.submit(() -> {
			Thread.currentThread().setName("thread zcq");
			log.info(Thread.currentThread().getName());
			log.info(String.valueOf(Thread.currentThread().getPriority()));
			return "callable";
		});
		System.out.println(future.get());
	}
}
